main: Warn if GDK sends us bad focus events
authorMatthias Clasen <mclasen@redhat.com>
Sun, 9 Jun 2019 14:09:20 +0000 (14:09 +0000)
committerMatthias Clasen <mclasen@redhat.com>
Sun, 9 Jun 2019 17:38:54 +0000 (17:38 +0000)
The new rule for focus events from the windowing
system is: We only want them for toplevels. If you
put focus on popups, we don't want to know about
it, and you still need to deliver key events to
the toplevel.

gtk/gtkmain.c

index c57c09e70e9e2298e3e27f5b99ae12cbd3f645b1..362800ee6df0f35e7897e0250f3a0cda6c61d3cd 100644 (file)
@@ -1658,6 +1658,20 @@ is_key_event (GdkEvent *event)
     }
 }
 
+static gboolean
+is_focus_event (GdkEvent *event)
+{
+  switch ((guint) event->any.type)
+    {
+    case GDK_FOCUS_CHANGE:
+      return TRUE;
+      break;
+    default:
+      return FALSE;
+    }
+}
+
+
 static inline void
 set_widget_active_state (GtkWidget       *target,
                          const gboolean   release)
@@ -1887,6 +1901,14 @@ gtk_main_do_event (GdkEvent *event)
 
       target_widget = handle_key_event (event);
     }
+  else if (is_focus_event (event))
+    {
+      if (!GTK_IS_WINDOW (target_widget))
+        {
+          g_message ("Ignoring an unexpected focus event from GDK on a non-toplevel surface.");
+          goto cleanup;
+        }
+    }
 
   if (!target_widget)
     goto cleanup;